//
//  Person+cg.m
//  testApp
//
//  Created by iMac on 2018/2/28.
//  Copyright © 2018年 iMac. All rights reserved.
//

#import "Person+cg.h"
#import <objc/runtime.h>


// 敞亮字符串, 作为key, 必须是c语言字符串
const char * str = "myKey";

void killPeople(id self, SEL _cmd, NSString *brand) {
    NSLog(@"brand: %@ will kill another person", brand);
}
//void killPeople(id self, SEL _cmd) {
//    NSLog(@"at finally he killed him self");
//}
@implementation Person (cg)

+ (BOOL)resolveInstanceMethod:(SEL)sel {
    if (sel == @selector(killPeople)) {
        class_addMethod([self class], sel, (IMP)killPeople, "v@:@");
        return YES;
    }
    return [super resolveInstanceMethod:sel];
}



- (void)setHeight:(float)height {
    NSNumber *num = [NSNumber numberWithFloat:height];
    objc_setAssociatedObject(self, str, num, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (float)height {
    NSNumber * num = objc_getAssociatedObject(self, str);
    return [num floatValue];
}

@end
